angular.module('app').controller('assetsCtrl', ['$scope', '$state', 'userInfo', 'utils', '$http', '$stateParams', 'product', function($scope, $state, userInfo, utils, $http, $stateParams, product) {

	$scope.goback = function() {
		window.history.go(-1)
	}

	/*交易记录*/
	if($state.current.name == "RecordList") {
		$scope.ScreenIsShow = false //筛选弹框
		$scope.RecordList = []
		$scope.offset = 0 //偏移量
		$scope.limit = 40 //数量
		$scope.trade_type = [] //筛选条件
		/*页面加载完成以后初始化下拉刷新*/
		$scope.$on('$viewContentLoaded', function(event) {
			var oh = document.documentElement.clientHeight
			var ow = document.documentElement.clientWidth
			/*设置滚动区域高度*/
			$("#pullrefresh").height((oh - 54) + 'px')
			$("#empty").height((oh - 54) + 'px').width(ow + 'px')
			mui("#pullrefresh").pullRefresh({
				down: {
					height: 50,
					callback: pulldownRefresh,
					auto: true
				},
				up: {
					height: 50, //可选.默认50.触发上拉加载拖动距离
					auto: true, //可选,默认false.自动上拉加载一次
					contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
					contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
					callback: pullfresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				}
			})

		});

		mui('.RecordList').on('tap', 'li', function() {
			$state.go("OrderDetails", {
				order_id: $(this).data("orderid"),
				product_type_pid: $(this).data("pid")
			})

		});

		/*下拉刷新*/
		function pulldownRefresh() {
			$scope.offset = 0 //偏移量
			$scope.limit = 40 //数量

			$http.get(utils.OrderSys, {
				params: {
					header: utils.header("010110"),
					body: {
						end_time: "",
						offset: $scope.offset,
						limit: $scope.limit,
						product_type_pid: "",
						start_time: "",
						trade_type: $scope.trade_type,
						user_code: userInfo.user_code
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					$scope.RecordList = res.body.list
				}

			})
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
			mui('#pullrefresh').pullRefresh().refresh(true);
		}

		/*上拉加载*/
		function pullfresh() {
			$scope.offset = $scope.offset + 40
			$http.get(utils.OrderSys, {
				params: {
					header: utils.header("010110"),
					body: {
						end_time: "",
						offset: $scope.offset,
						limit: $scope.limit,
						product_type_pid: "",
						start_time: "",
						trade_type: $scope.trade_type,
						user_code: userInfo.user_code
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					if(res.body.list.length > 0) {
						$scope.RecordList = $scope.RecordList.concat(res.body.list)
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(false)
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(true)
					}
				}

			})
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh();

		}

		mui(document).on("tap", ".Record_screen li", function() {
			$(this).addClass("active").siblings().removeClass("active")
			var arr = $(this).attr("trade_type").split(",")
			if(!arr[0]) {
				arr = []
			}
			$scope.trade_type = arr //设置筛选条件
			$scope.ScreenIsShow = false //关闭弹窗
			pulldownRefresh()
		})

	}
	/*订单详细*/
	if($state.current.name == "OrderDetails") {

		$http.get(utils.OrderSys, {
			params: {
				header: utils.header("010060"),
				body: {
					order_id: $stateParams.order_id
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.orderInfo = res.body
				userInfo.getUserBank().then(function(res) {
					if(res.header.re_code == "0000") {
						angular.extend($scope.orderInfo, res.body.card)
						$scope.orderInfo.product_type_pid = $stateParams.product_type_pid
						$scope.orderInfo.yu = $stateParams.amount
						$scope.iswallet = $stateParams.iswallet
					}

				})

			}
		})

	}

	/*定期资产详情*/
	if($state.current.name == "regular") {
		$scope.VpwdShow = false
		$scope.pwd = null //交易密码
		$scope.temp = {} //临时存储资产信息
		$scope.title = product.assetsInfo.product_name; //设置标题
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000022"),
				body: {
					page_index: 1,
					page_size: 100,
					product_type_id: product.assetsInfo.product_type_id,
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.regularInfo = res.body
			}

		})
		/*点击复投*/
		$scope.checkd = function(item) {

			if(item.is_new_user_mark == 0) {
				utils.msg("新手专享产品不支持到期复投")
				return
			}

			if(item.remain_return_day <= 1) {
				utils.msg("还款中及倒计时为1天时，不能改变复投状态")
				return
			} else {
				$scope.VpwdShow = true //显示弹窗
				$scope.temp = item
			}
		}
		/*验证密码复投*/
		$scope.isReinvest = function() {
			/*验证交易密码*/
			var state = $scope.temp.is_reinvest == 0 ? 1 : 0
			$http.get(utils.userSys, {
					params: {
						header: utils.header("070114"),
						body: {
							user_code: userInfo.user_code,
							tra_password: md5($scope.pwd)
						}
					}
				})
				.then(function(res) {
					if(res.header.re_code == "0000") {
						/*更新资产状态*/
						$http.post(utils.balanceSys, {}, {
							params: {
								header: utils.header("000025"),
								body: {
									assets_id: $scope.temp.assets_id,
									is_reinvest: state
								}
							}
						}).then(function(res) {
							if(res.header.re_code == "0000") {
								$scope.temp.is_reinvest = $scope.temp.is_reinvest == 0 ? 1 : 0
								$scope.VpwdShow = false
							}
						})
					}
				})

		}

		$scope.$on('$viewContentLoaded', function(event) {
			var oh = document.documentElement.clientHeight
			var ow = document.documentElement.clientWidth
			/*设置滚动区域高度*/
			$("#empty").height((oh - $("#empty").offset().top) + 'px').width(ow + 'px')
		})

		$scope.details = function(item) {
			product.regularInfo = item
			$state.go("regular_details")

		}

		$scope.send = function() {
			product.profitInfo.product_type_id = product.assetsInfo.product_type_id
			product.profitInfo.intrest_total = $scope.regularInfo.intrest_total
			product.profitInfo.product_name = product.assetsInfo.product_name
			$state.go("profit_details")
		}

	}
	
	
	/*散标详情*/
	if($state.current.name == "disperse") {
		$scope.temp = {} //临时存储资产信息
		$scope.title = product.assetsInfo.product_name; //设置标题
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000027"),
				body: {
					page_index: 1,
					page_size: 100,
					product_type_id: product.assetsInfo.product_type_id,
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.regularInfo = res.body
			}

		})
		
	

		$scope.$on('$viewContentLoaded', function(event) {
			var oh = document.documentElement.clientHeight
			var ow = document.documentElement.clientWidth
			/*设置滚动区域高度*/
			$("#empty").height((oh - $("#empty").offset().top) + 'px').width(ow + 'px')
		})

		$scope.details = function(item) {
			product.regularInfo = item
			$state.go("disperse_details")

		}

		$scope.send = function() {
			product.profitInfo.product_type_id = product.assetsInfo.product_type_id
			product.profitInfo.intrest_total = $scope.regularInfo.intrest_total
			product.profitInfo.product_name = product.assetsInfo.product_name
			$state.go("profit_details")
		}

	}

	
	
	
	

	/*已到期*/
	if($state.current.name == "Expired") {
		$scope.page_index = 1
		$scope.page_size = 40
		$scope.$on('$viewContentLoaded', function(event) {
			var oh = document.documentElement.clientHeight
			var ow = document.documentElement.clientWidth
			/*设置滚动区域高度*/
			$("#pullrefresh").height((oh - 54) + 'px')
			$("#empty").height((oh - 54) + 'px').width(ow + 'px')
			mui("#pullrefresh").pullRefresh({
				down: {
					height: 50,
					callback: pulldownRefresh,
					auto: true
				},
				up: {
					height: 50, //可选.默认50.触发上拉加载拖动距离
					auto: true, //可选,默认false.自动上拉加载一次
					contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
					contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
					callback: pullfresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				}
			})

		});

		function pulldownRefresh() {
			$scope.page_index = 1
			$scope.page_size = 40
			$http.post(utils.balanceSys, {}, {
				params: {
					header: utils.header("000024"),
					body: {
						is_reinvest: 1,
						page_index: $scope.page_index,
						page_size: $scope.page_size,
						prod_type: product.assetsInfo.product_type_pid,
						status: 1,
						user_id: userInfo.user_code
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					$scope.expired = res.body
				}

			})
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
			mui('#pullrefresh').pullRefresh().refresh(true);

		}

		function pullfresh() {

			$scope.page_index = $scope.page_index + 40

			$http.post(utils.balanceSys, {}, {
				params: {
					header: utils.header("000024"),
					body: {
						is_reinvest: 1,
						page_index: $scope.page_index,
						page_size: $scope.page_size,
						prod_type: product.assetsInfo.product_type_pid,
						status: 1,
						user_id: userInfo.user_code
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					if(res.body.length > 0) {
						$scope.expired = $scope.expired.concat(res.body)
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(false)
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(true)
					}
				}
			})
		}
	}
	
	
	/*散标资产详情*/
	if($state.current.name == "disperse_details"){
		
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000028"),
				body: {
					assets_id: product.regularInfo.assets_id,
					prod_id: product.regularInfo.prod_Id,
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.regular_details = res.body
				$scope.regularInfo = product.regularInfo
				$("#yuqi").html($scope.regular_details.intrest_total_estimate+"元")
			}
		})

		$scope.gourl = function(urls) {

			$state.go(urls, {
				assetsId: $scope.regularInfo.assets_id,
				type: product.assetsInfo.product_type_pid
			})
		}
		
		
		
		
	}
	

	/*定期资产详情*/
	if($state.current.name == "regular_details") {
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000021"),
				body: {
					assets_id: product.regularInfo.assets_id,
					prod_id: product.regularInfo.prod_Id,
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.regular_details = res.body
				$scope.regularInfo = product.regularInfo
				$("#yuqi").html($scope.regular_details.intrest_total_estimate+"元")
			}
		})

		$scope.gourl = function(urls) {

			$state.go(urls, {
				assetsId: $scope.regularInfo.assets_id,
				type: product.assetsInfo.product_type_pid
			})
		}
		

	}
	
	
	/*加息券详情*/
	if($state.current.name == "Increase"){
		
		$http.post(utils.balanceSys,{},{
			params: {
				header: utils.header("000051"),
				body: {
					assets_id:$stateParams.assetsId,
					prod_type:$stateParams.type
				}
			}
		}).then(function(res){
			if(res.header.re_code=="0000"){
				
				$scope.IncreaseList=res.body
				
			}
		})
		
		
	}
	
	
	

	/*活期资产详情*/
	if($state.current.name == "current") {
		$scope.currentInfo = {
			currCapValue: 0,
			intreTotal: 0,
			intreYesterday: 0,
			transCapValue: 0,
			assetsFundList: []
		}
		$scope.title = product.assetsInfo.product_name //设置标题
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000019"),
				body: {
					product_type_id: product.assetsInfo.product_type_id,
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {

			if(res.header.re_code == "0000") {
				$scope.currentInfo = res.body
			}

		})

		$scope.$on('$viewContentLoaded', function(event) {
			setTimeout(function() {
				$(".currentList").height($(window).height() - $(".currentList").offset().top - 60)
				mui('.mui-scroll-wrapper').scroll({
					scrollY: true, //是否竖向滚动
					scrollX: false, //是否横向滚动
					startX: 0, //初始化时滚动至x
					startY: 0, //初始化时滚动至y
					indicators: false, //是否显示滚动条
					deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
					bounce: true //是否启用回弹
				});
			}, 200)

		})

		/*跳转活期资产详情*/
		$scope.details = function(item, prodid) {
			product.currentProdId = prodid //活期prodid
			product.currentInfo = item
			$state.go("current_details")
		}

		$scope.send = function() {
			product.profitInfo.product_type_id = product.assetsInfo.product_type_id
			product.profitInfo.intrest_total = $scope.currentInfo.intreTotal
			product.profitInfo.product_name = product.assetsInfo.product_name
			$state.go("profit_details")
		}
	}

	/*活期资产详情*/
	if($state.current.name == "current_details") {
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000021"),
				body: {
					assets_id: product.currentInfo.assets_id,
					prod_id: product.currentProdId,
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.current_details = res.body
				$scope.currentInfo = product.currentInfo
			}
		})

		$scope.gourl = function() {

			$state.go("bondList", {
				assetsId: $scope.currentInfo.assets_id,
				type: product.assetsInfo.product_type_pid
			})
		}

	}

	/*转让*/
	if($state.current.name == "current_attorn") {

		$scope.pwd = ""
		$scope.VpwdShow = false

		$scope.close = function() {
			window.history.go(-1)
		}

		/*提交按钮*/
		$scope.tijiao = function() {
			if($scope.arr.length > 0) {
				$scope.VpwdShow = true
			}
		}

		/*发送请求*/
		$scope.send = function() {

			$http.get(utils.userSys, {
					params: {
						header: utils.header("070114"),
						body: {
							user_code: userInfo.user_code,
							tra_password: md5($scope.pwd)
						}
					}
				})
				.then(function(res) {
					if(res.header.re_code == "0000") {
						/*更新资产状态*/
						$http.post(utils.balanceSys, {}, {
							params: {
								header: utils.header("000033"),
								body: $scope.arr
							}
						}).then(function(res) {
							if(res.header.re_code == "0000") {

								$state.go("current_attorn_details")
							}
						})

					}
				})

		}

		$scope.All = false //是否全选

		/*选择*/
		$scope.checks = function(m) {
			for(var i = 0; i < $scope.currentInfo.assetsFundList.length; i++) {
				if(m === true) {
					$scope.currentInfo.assetsFundList[i].state = true;
				} else {
					$scope.currentInfo.assetsFundList[i].state = false;
				}
			}

		}

		$scope.$watch("currentInfo", function(n, o) {
			$scope.arr = [] //数组
			$scope.zong = 0
			if($scope.currentInfo) {
				angular.forEach($scope.currentInfo.assetsFundList, function(v, k) {
					if(v.state === true) {
						$scope.zong += v.calAmount
						$scope.arr.push({
							"assets_id": v.assets_id
						})
						product.attorn.name = v.prodName
						product.attorn.price = $scope.zong
					}
				})
			}
		}, true)

		/*获取转让列表*/
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000019"),
				body: {
					product_type_id: product.assetsInfo.product_type_id,
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {

			if(res.header.re_code == "0000") {
				$scope.currentInfo = res.body
				angular.forEach($scope.currentInfo.assetsFundList, function(v, k) {
					v.state = false
				})
			}

		})

		$scope.$on('$viewContentLoaded', function(event) {
			setTimeout(function() {
				$(".mui-content").height($(window).height() - 54 + "px")
				$(".currentList").height($(window).height() - $(".currentList").offset().top - 60 + "px")
				mui('.mui-scroll-wrapper').scroll({
					scrollY: true, //是否竖向滚动
					scrollX: false, //是否横向滚动
					startX: 0, //初始化时滚动至x
					startY: 0, //初始化时滚动至y
					indicators: false, //是否显示滚动条
					deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
					bounce: true //是否启用回弹
				});
			}, 200)

		})

	}

	/*活期转让订单详情*/
	if($state.current.name == "current_attorn_details") {
		$scope.attorn = product.attorn
	}

	/*活期转让中*/
	if($state.current.name == "current_attorn_list") {
		$scope.$on('$viewContentLoaded', function(event) {
			setTimeout(function() {
				$(".mui-content").height($(window).height() - 54 + "px")
				$(".currentList").height($(window).height() - $(".currentList").offset().top - 5 + "px")
				mui('.mui-scroll-wrapper').scroll({
					scrollY: true, //是否竖向滚动
					scrollX: false, //是否横向滚动
					startX: 0, //初始化时滚动至x
					startY: 0, //初始化时滚动至y
					indicators: false, //是否显示滚动条
					deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
					bounce: true //是否启用回弹
				});
			}, 200)

		})

		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000024"),
				body: {
					is_reinvest: 1,
					status: 0,
					prod_type: 4,
					user_id: userInfo.user_code,
					page_index: 1,
					page_size: 40
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {

				$scope.attorn_list = res.body

			}

		})

	}

	/*累计利息*/
	if($state.current.name == "profit") {
		/*昨日利息*/
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000016"),
				body: {
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.yesterday = res.body
				if($scope.yesterday.prodYesterdayIntrest.length > 0) {
					angular.forEach($scope.yesterday.prodYesterdayIntrest, function(value, index) {
						if(index == 0) {
							value.color = "#F9803E"
						} else if(index == 1) {
							value.color = "#FF635b"
						} else if(index == 2) {
							value.color = "#FEBF56"
						} else if(index == 3) {
							value.color = "#69c5ff"
						} else if(index == 4) {
							value.color = "#f2a3da"
						} else {
							value.color = '#' + Math.floor(Math.random() * 0xffffff).toString(16);
						}

					})
				}

			}
		})
		/*累计利息*/
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000015"),
				body: {
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.Cumulative = res.body
				if($scope.Cumulative.prodTotalIntrest.length > 0) {
					angular.forEach($scope.Cumulative.prodTotalIntrest, function(value, index) {
						if(index == 0) {
							value.color = "#F9803E"
						} else if(index == 1) {
							value.color = "#FF635b"
						} else if(index == 2) {
							value.color = "#FEBF56"
						} else if(index == 3) {
							value.color = "#69c5ff"
						} else if(index == 4) {
							value.color = "#f2a3da"
						} else {
							var r = Math.floor(Math.random() * 256);
							var g = Math.floor(Math.random() * 256);
							var b = Math.floor(Math.random() * 256);
							value.color = "rgb(" + r + ',' + g + ',' + b + ")";
						}

					})
				}
			}
		})

		$scope.send = function(index) {
			product.profitInfo = $scope.Cumulative.prodTotalIntrest[index]
			$state.go("profit_details")
		}

	}

	/*收益列表*/
	if($state.current.name == "profit_details") {
		$scope.page_index = 1
		$scope.page_size = 40
		$scope.profitInfo = product.profitInfo
		$scope.profitList = []
		$scope.$on('$viewContentLoaded', function(event) {

			mui("#pullrefresh").pullRefresh({
				up: {
					height: 50, //可选.默认50.触发上拉加载拖动距离
					auto: true, //可选,默认false.自动上拉加载一次
					contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
					contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
					callback: pullfresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				}

			})

			setTimeout(function() {
				$(".profit_details").height($(window).height() - $(".profit_details").offset().top)
				mui('.mui-scroll-wrapper').scroll({
					scrollY: true, //是否竖向滚动
					scrollX: false, //是否横向滚动
					startX: 0, //初始化时滚动至x
					startY: 0, //初始化时滚动至y
					indicators: false, //是否显示滚动条
					deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
					bounce: true //是否启用回弹
				});
			}, 200)

		})

		function pullfresh() {
			$http.post(utils.balanceSys, {}, {
				params: {
					header: utils.header("000014"),
					body: {
						page_index: $scope.page_index,
						page_size: $scope.page_size,
						product_type_id: $scope.profitInfo.product_type_id,
						user_id: userInfo.user_code
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					if(res.body.length > 0) {
						$scope.profitList = $scope.profitList.concat(res.body)
						var maxArr = $scope.profitList.slice(0)
						maxArr.sort(function(a, b) {
							return b.amout_total - a.amout_total
						})
						$scope.max = maxArr[0].amout_total

						mui('#pullrefresh').pullRefresh().endPullupToRefresh(false)
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(true)
					}

					$scope.page_index = $scope.page_index + 40
				}
			})

		}

	}

	/*资产分布*/
	if($state.current.name == "distribution") {

		$scope.assetsCurrentTotal = product.assetsCurrentTotal
		$scope.wallet = product.acc_amount
		$http.post(utils.balanceSys, {}, {
			params: {
				header: utils.header("000032"),
				body: {
					user_id: userInfo.user_code
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				var echartArr = []
				$scope.AssetsList = res.body
				angular.forEach($scope.AssetsList, function(value, index) {
					if(index == 0) {
						value.color = "#ff635b"
					} else if(index == 1) {
						value.color = "#FEBF56"
					} else if(index == 2) {
						value.color = "#168fdc"
					} else if(index == 3) {
						value.color = "#f2a3d2"
					} else if(index == 4) {
						value.color = "#69c5ff"
					} else {
						var r = Math.floor(Math.random() * 256);
						var g = Math.floor(Math.random() * 256);
						var b = Math.floor(Math.random() * 256);
						value.color = "rgb(" + r + ',' + g + ',' + b + ")";
					}
					echartArr.push({
						"value": value.currCapValue,
						"itemStyle": {
							"normal": {
								"color": value.color
							}
						}
					})
				})
				echartArr.push({
					value: parseFloat(product.acc_amount),
					"itemStyle": {
						"normal": {
							"color": "#69c5ff"
						}
					}
				})
				var myChart = echarts.init(document.getElementById('echarts'));
				var option = {
					grid: {
						top: "22",
						bottom: "22",
						left: "10%",
						right: "10%",

					},
					backgroundColor: "#fff",
					series: [{
						type: 'pie',
						startAngle: -45,
						radius: ['50%', '70%'],
						avoidLabelOverlap: false,
						label: {
							normal: {
								show: true,
								position: "center",
								formatter: function() {
									return $scope.assetsCurrentTotal + "\n\n总资产 (元) "
								},
								color: "#000",
								fontFamily: "Microsoft YaHei"
							}
						},
						labelLine: {
							normal: {
								show: false
							}
						},
						data: echartArr
					}]
				};
				myChart.setOption(option);

			}
		})

		$scope.gotoUrl = function(item) {
			product.assetsInfo = item
			if(item.product_type_pid == 4) {
				$state.go("current")
			} else if(item.product_type_pid == 3) {
				$state.go("regular")
			}
		}

	}

	/*钱包*/
	if($state.current.name == "wallet") {
		$scope.wallet = product.acc_amount
		$http.get(utils.userSys, {
			params: {
				header: utils.header("070118"),
				body: {
					user_code: userInfo.user_code,
					acc_id: userInfo.acc_id
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {

				$scope.cashInfo = res.body

			}
		})

		$scope.getPay = function(url) {
			var promise = userInfo.getUserInfo()
			promise.then(function(res) {
				/*未实名*/
				if(res.is_real_name == 0) {
					$state.go("Realname")
					return
				}
				/*未绑卡*/
				if(res.is_bind_card == 0) {
					$state.go("BindBank")
					return
				}
				/*未设置交易密码*/
				if(res.is_tra_password == 0) {
					$state.go("SetTradePassword")
					return
				}

				$state.go(url)
			})
		}

	}

	/*收支明细*/
	if($state.current.name == "collect_details") {

		$scope.ScreenIsShow = false //筛选弹框
		$scope.RecordList = []
		$scope.offset = 1 //偏移量
		$scope.limit = 40 //数量
		$scope.trade_type = 0 //筛选条件
		/*页面加载完成以后初始化下拉刷新*/
		$scope.$on('$viewContentLoaded', function(event) {
			var oh = document.documentElement.clientHeight
			var ow = document.documentElement.clientWidth
			/*设置滚动区域高度*/
			$("#pullrefresh").height((oh - 54) + 'px')
			$("#empty").height((oh - 54) + 'px').width(ow + 'px')
			mui("#pullrefresh").pullRefresh({
				down: {
					height: 50,
					callback: pulldownRefresh,
					auto: true
				},
				up: {
					height: 50, //可选.默认50.触发上拉加载拖动距离
					contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
					contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
					callback: pullfresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				}
			})

		});

		mui('.RecordList').on('tap', 'li', function() {
			$state.go("OrderDetails", {
				order_id: $(this).data("orderid"),
				product_type_pid: $(this).data("pid"),
				iswallet: 1,
				amount: $(this).data("amount")
			})

		});

		/*下拉刷新*/
		function pulldownRefresh() {
			$scope.offset = 1 //偏移量
			$scope.limit = 40 //数量

			$http.get(utils.userSys, {
				params: {
					header: utils.header("070129"),
					body: {
						page_num: $scope.offset,
						page_size: $scope.limit,
						order_type: $scope.trade_type,
						acc_id: userInfo.acc_id
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					$scope.RecordList = res.body
				}

			})
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
			mui('#pullrefresh').pullRefresh().refresh(true);
		}

		/*上拉加载*/
		function pullfresh() {
			$scope.offset = $scope.offset + 1
			$http.get(utils.userSys, {
				params: {
					header: utils.header("070129"),
					body: {
						page_num: $scope.offset,
						page_size: $scope.limit,
						order_type: $scope.trade_type,
						acc_id: userInfo.acc_id
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					if(res.body.length > 0) {
						$scope.RecordList = $scope.RecordList.concat(res.body)
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(false)
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(true)
					}
				}

			})
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh();

		}

		mui(document).on("tap", ".Record_screen li", function() {
			$(this).addClass("active").siblings().removeClass("active")
			$scope.trade_type = $(this).attr("trade_type") //设置筛选条件
			$scope.ScreenIsShow = false //关闭弹窗
			pulldownRefresh()
		})

	}

	/*提现*/
	if($state.current.name == "cash") {
		/*获取绑卡信息*/
		userInfo.getUserBank().then(function(res) {
				if(res.header.re_code == "0000") {
					$scope.userBankInfo = res.body.card
					return $http.get(utils.userSys, {
						params: {
							header: utils.header("070118"),
							body: {
								user_code: userInfo.user_code,
								acc_id: res.body.card.acc_id
							}
						}
					})
				} else {
					throw 0
				}
			})
			/*提现前置条件*/
			.then(function(res) {
				if(res.header.re_code == "0000") {
					angular.extend($scope.userBankInfo, res.body)
					return $http.get(utils.userSys, {
						params: {
							header: utils.header("070070"),
							body: {
								birth_day: "",
								home_address: "",
								id_number: "",
								id_type: "",
								marry_status: "",
								operation_type: 1,
								phone_id: "",
								phone_number: "",
								real_name: "",
								sex: "",
								user_code: userInfo.user_code
							}
						}
					})
				} else {
					throw 0
				}
			})
			/*获取用户身份信息*/
			.then(function(res) {
				if(res.header.re_code == "0000") {
					angular.extend($scope.userBankInfo, res.body[0])
				}

			})
			.catch(function() {

			})

		/*提交*/
		$scope.cashSend = function() {
			if(Number($scope.CashMoney) > Number($scope.userBankInfo.amt_all)) {
				return utils.msg("可提金额不足!")
			}
			/*创建订单*/
			$http.get(utils.OrderSys, {
					params: {
						header: utils.header("010010"),
						body: {
							acc_id: $scope.userBankInfo.acc_id,
							acc_number: $scope.userBankInfo.acc_number,
							amount: $scope.CashMoney,
							order_source: "",
							order_type: "5",
							pro_id: "",
							pro_num: "",
							pro_type: "",
							red_packet_list: "",
							user_code: userInfo.user_code
						}
					}
				})
				/*提现申请*/
				.then(function(res) {
					if(res.header.re_code == "0000") {
						$scope.userBankInfo.order_id = res.body.order_id //保存订单号
						$scope.userBankInfo.money = $scope.CashMoney //保存金额
						return $http.get(utils.tradeSys, {
							params: {
								header: utils.header("000018"),
								body: {
									acc_id: $scope.userBankInfo.acc_id,
									amount: $scope.CashMoney,
									bank_name: $scope.userBankInfo.bank_name,
									id_number: $scope.userBankInfo.id_number,
									item_id: 2,
									order_id: res.body.order_id,
									phone_number: $scope.userBankInfo.phone_number,
									real_name: $scope.userBankInfo.real_name,
									user_code: userInfo.user_code
								}
							}
						})

					} else {
						throw 0
					}

				})
				/*获取手续费*/
				.then(function(res) {
					if(res.header.re_code == "0000") {

						if(res.body.deduct_service_amt > 0) {
							mui.confirm('提现<font color="#fb5a5c;font-weight:bold;">手续费：'+res.body.deduct_service_amt+'元</font>，是否继续？<br><font style="font-size:12px;color:#999">收费规则可点击页面右上角按钮查看。</font>', '  ', ['取消', '继续'], function(e) {
								if(e.index === 0) {
									return
								} else {
									angular.extend($scope.userBankInfo, res.body)
									userInfo.cashInfo = $scope.userBankInfo
									$state.go("cash_confirm")
								}
							}, 'div')
						} else {
							angular.extend($scope.userBankInfo, res.body)
							userInfo.cashInfo = $scope.userBankInfo
							$state.go("cash_confirm")
						}

					}
				})
				.catch(function() {

				})

		}

		/*限制两位*/
		$scope.$watch("CashMoney", function(value, o) {
			if(value) {
				if(value[0] == 0 && value[1] != "." && value[1]) {
					value = ""
				}
				value = value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符  
				value = value.replace(/^\./g, ""); //验证第一个字符是数字而不是  
				value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的  
				value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
				$scope.CashMoney = value
			}

		})

	}

	/*提现确认*/
	if($state.current.name == "cash_confirm") {
		$scope.cashInfo = userInfo.cashInfo
		/*提现确认*/
		$scope.cashSend = function() {

			$http.get(utils.tradeSys, {
				params: {
					header: utils.header("000019"),
					body: {
						acc_id: $scope.cashInfo.acc_id,
						item_id: 2,
						order_id: $scope.cashInfo.order_id,
						phone_number: $scope.cashInfo.phone_number,
						tra_password: md5($scope.pwd),
						user_code: userInfo.user_code
					}
				}
			}).then(function(res) {
				if(res.header.re_code == "0000") {
					$state.go("cash_Order")
				}

			})

		}
		$scope.resetPwd = function() {
			$state.go("BackTradePwd")
		}

	}

	/*提现订单详情*/
	if($state.current.name == "cash_Order") {
		$scope.cashInfo = userInfo.cashInfo
		$http.get(utils.OrderSys, {
			params: {
				header: utils.header("010060"),
				body: {
					order_id: $scope.cashInfo.order_id
				}
			}
		}).then(function(res) {
			if(res.header.re_code == "0000") {
				$scope.orderInfo = res.body
				$scope.times = new Date().getHours()
			}

		})
	}

}])